package ocean.chinacraft.common.world.item.festival;

import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.world.World;
import ocean.chinacraft.common.config.GroupDefine;
import ocean.chinacraft.common.entity.projectile.FirecrackerEntity;

/**
 * 鞭炮
 *
 * @author zhang
 * @since 2021/12/24
 */
public class Firecracker extends Item {
    public Firecracker() {
        super(new Properties().tab(GroupDefine.CHINACRAFT_MISC).stacksTo(16));
    }

    @Override
    public ActionResult<ItemStack> use(World world, PlayerEntity player, Hand hand) {
        ItemStack itemstack = player.getItemInHand(hand);
        if (!world.isClientSide) {
            FirecrackerEntity firecracker = new FirecrackerEntity(world, player);
            firecracker.shootFromRotation(player, player.xRot, player.yRot, 0.0F, 1.5F, 1.0F);
            world.addFreshEntity(firecracker);
        }
        if (!player.abilities.instabuild) {
            itemstack.shrink(1);
        }
        return ActionResult.sidedSuccess(itemstack, world.isClientSide());
    }
}
